package com.datamining.web.controller.wali;

import com.datamining.common.core.domain.AjaxResult;
import com.datamining.common.core.domain.entity.BusStuPaper;
import com.datamining.system.service.IBusStuPaperService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 试卷分析
 * 
 * @author datamining
 */
@Api("试卷分析")
@RestController
@RequestMapping("/paper")
public class BusStuPaperController
{
    private static final Logger log = LoggerFactory.getLogger(BusStuPaperController.class);

    @Resource
    private IBusStuPaperService busStuPaperService;

    /**
     * 开始分析单张试卷
     */
    @ApiOperation("开始分析单张试卷")
    @PostMapping("/one/analysis")
    public AjaxResult uploadFile(@RequestParam("url") String url) throws Exception
    {
        try
        {
            AjaxResult ajax = AjaxResult.success();
//            ajax.put("url", url);
//            ajax.put("fileName", fileName);
//            ajax.put("newFileName", FileUtils.getName(fileName));
//            ajax.put("originalFilename", file.getOriginalFilename());
            ajax.put("msg","Success");
            return ajax;
        }
        catch (Exception e)
        {
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 开始分析多张试卷
     */
    @ApiOperation("开始分析多张试卷")
    @PostMapping("/more/analysis")
    public AjaxResult uploadFiles(@RequestParam("urls") List<String> urls) throws Exception
    {
        try
        {
            for (String url : urls)
            {
                // 上传并返回新文件名称
//                String fileName = FileUploadUtils.upload(filePath, file);
//                String url = serverConfig.getUrl() + fileName;
//                urls.add(url);
//                fileNames.add(fileName);
//                newFileNames.add(FileUtils.getName(fileName));
//                originalFilenames.add(file.getOriginalFilename());
            }
            List<BusStuPaper> list = busStuPaperService.selectBusStuPaper(new BusStuPaper());
            AjaxResult ajax = AjaxResult.success();
            ajax.put("msg","Success");
            ajax.put("data",list);
            return ajax;
        }
        catch (Exception e)
        {
            return AjaxResult.error(e.getMessage());
        }
    }

}
